package com.demo.jvm.structure.constant.parser;

import com.demo.jvm.structure.constant.CONSTANT_NameAndType_info;
import com.demo.jvm.structure.constant.CONSTANT_info;

import java.io.DataInputStream;

/**
 * CONSTANT_NameAndType_info {
 * u1 tag;
 * u2 name_index;
 * u2 descriptor_index;
 * }
 */
public class CONSTANT_NameAndType_info_Parser {
    private DataInputStream dis;

    public CONSTANT_NameAndType_info_Parser(DataInputStream dis) {
        this.dis = dis;
    }

    public CONSTANT_info readValue(int tableIndex) {
        try {
            int nameIndex = dis.readUnsignedShort();
            int descriptorIndex = dis.readUnsignedShort();
            return new CONSTANT_NameAndType_info((byte) 12, tableIndex, nameIndex, descriptorIndex);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
